#!/bin/bash
#################检测文件是否存在
if [ $# -lt 1 ];then
echo "没有接收到参数，退出"
echo "用法：$0 版本号"
echo "此脚本会获取游戏本体和语音包下载链接，暂时没做增量包获取相关逻辑"
exit
fi


version="$1"

mkdir -p /tmp/getdownloadurl
cd /tmp/getdownloadurl
wget -O downloadurl.json "https://sdk-static.mihoyo.com/hk4e_cn/mdk/launcher/api/resource?key=eYd89JmJ&launcher_id=18"
cat /tmp/getdownloadurl/downloadurl.json | jq . > /tmp/getdownloadurl/paths.json
yuanshen_game=`cat /tmp/getdownloadurl/paths.json | grep https://autopatchcn.yuanshen.com | grep YuanShen_$version.zip`
yuanshen_audio=`cat /tmp/getdownloadurl/paths.json | grep https://autopatchcn.yuanshen.com | grep Audio_Chinese_$version.zip`
####得到json
####切去不要的
yuanshen_game=`echo ${yuanshen_game#*\"path\": \"} `
yuanshen_game=`echo ${yuanshen_game%\",*} `

yuanshen_audio=`echo ${yuanshen_audio#*\"path\": \"} `
yuanshen_audio=`echo ${yuanshen_audio%\",*} `

if [ "$yuanshen_game" = "" ];then
echo "无法获取到下载链接，检查版本号或者网络连接"
exit 1
fi

echo $yuanshen_game
echo $yuanshen_audio
rm -rf /tmp/getdownloadurl

